home *** CD-ROM | disk | FTP | other *** search
/ NOVA - For the NeXT Workstation / NOVA - For the NeXT Workstation.iso / SourceCode / AdobeExamples / NX_ImportInt / Document.m < prev    next >
Encoding:
Text File  |  1992-12-19  |  3.7 KB  |  160 lines

  1.  
  2. /*
  3.  * (a)  (C) 1990 by Adobe Systems Incorporated. All rights reserved.
  4.  *
  5.  * (b)  If this Sample Code is distributed as part of the Display PostScript
  6.  *    System Software Development Kit from Adobe Systems Incorporated,
  7.  *    then this copy is designated as Development Software and its use is
  8.  *    subject to the terms of the License Agreement attached to such Kit.
  9.  *
  10.  * (c)  If this Sample Code is distributed independently, then the following
  11.  *    terms apply:
  12.  *
  13.  * (d)  This file may be freely copied and redistributed as long as:
  14.  *    1) Parts (a), (d), (e) and (f) continue to be included in the file,
  15.  *    2) If the file has been modified in any way, a notice of such
  16.  *      modification is conspicuously indicated.
  17.  *
  18.  * (e)  PostScript, Display PostScript, and Adobe are registered trademarks of
  19.  *    Adobe Systems Incorporated.
  20.  * 
  21.  * (f) THE INFORMATION BELOW IS FURNISHED AS IS, IS SUBJECT TO
  22.  *    CHANGE WITHOUT NOTICE, AND SHOULD NOT BE CONSTRUED
  23.  *    AS A COMMITMENT BY ADOBE SYSTEMS INCORPORATED.
  24.  *    ADOBE SYSTEMS INCORPORATED ASSUMES NO RESPONSIBILITY
  25.  *    OR LIABILITY FOR ANY ERRORS OR INACCURACIES, MAKES NO
  26.  *    WARRANTY OF ANY KIND (EXPRESS, IMPLIED OR STATUTORY)
  27.  *    WITH RESPECT TO THIS INFORMATION, AND EXPRESSLY
  28.  *    DISCLAIMS ANY AND ALL WARRANTIES OF MERCHANTABILITY, 
  29.  *    FITNESS FOR PARTICULAR PURPOSES AND NONINFRINGEMENT
  30.  *    OF THIRD PARTY RIGHTS.
  31.  */
  32.  
  33. /*
  34.  *     Document.m
  35.  *
  36.  *    Portions of the source code in this file are based on source code
  37.  *    from the Draw example application provided by NeXT.
  38.  *
  39.  *    The Document class serves to keep track of the global information
  40.  *    concerning a particular file. It sets up the window and the view.
  41.  *
  42.  *    Version:    2.0
  43.  *    Author:    Ken Fromm
  44.  *    History:
  45.  *            03-07-91        Added this comment.
  46.  */
  47.  
  48. #import "Document.h"
  49. #import "ImportApp.h"
  50. #import "DrawingView.h"
  51. #import "SaveAsPanel.h"
  52.  
  53. #import <appkit/Matrix.h>
  54. #import <appkit/OpenPanel.h>
  55. #import <appkit/nextstd.h>
  56. #import <appkit/publicWraps.h>
  57. #import <objc/hashtable.h>
  58. #import <string.h>
  59.  
  60. const NXRect            DefaultWindowRect = {300.0, 110.0, 575.0, 660.0};
  61.  
  62. @implementation Document
  63.  
  64. /*
  65.  *    Creates a new, empty, document.
  66.  */
  67. + new
  68. {
  69.     self = [super new];
  70.  
  71.     [self  createWindow];
  72.     [self  setWindow];
  73.  
  74.     return self;
  75. }
  76.  
  77. - setWindow
  78. {
  79.     [windowId  makeFirstResponder:[windowId  contentView]];
  80.     [windowId  setDelegate:self];
  81.     [windowId  setTitle:"Epsf Introduction"];
  82.     [windowId  display];
  83.  
  84.     [windowId  makeKeyAndOrderFront:self];
  85.  
  86.     return self;
  87. }
  88.  
  89. /*
  90. *    Create the drawing window and place a scrollview as the content view.
  91. *    A DrawingView instance is placed as the DocView of the ScrollView.
  92. */
  93. - createWindow
  94. {
  95.     id                drawingView;
  96.  
  97.     drawingView = [DrawingView  newFrame:&DefaultWindowRect];
  98.     windowId = [Window newContent:&DefaultWindowRect
  99.             style:NX_TITLEDSTYLE
  100.             backing:NX_BUFFERED
  101.             buttonMask:0
  102.             defer:NO];
  103.     [[windowId  setContentView:drawingView]  free];
  104.  
  105.     return self;
  106. }
  107.  
  108. - window
  109. {
  110.     return windowId;
  111. }
  112.  
  113. - (char const *) filename
  114. {
  115.     return [[SaveAsPanel  new]  filename];
  116. }
  117.  
  118. /*
  119. *    Bring up the import (open) panel to obtain the file and then pass
  120. *    to the drawing view.
  121. */
  122. - import:sender
  123. {
  124.     id                        openpanel;
  125.  
  126.     static const char *const        filetype[4] = {"ps", "eps", "tiff", NULL};
  127.  
  128.     openpanel = [OpenPanel  new];
  129.     if ([openpanel runModalForTypes:filetype])
  130.         [[windowId  contentView]  importFile:[openpanel  filename]];
  131.  
  132.     return self;
  133. }
  134.  
  135. - saveTo:sender
  136. {
  137.     id            savepanel;
  138.  
  139.     NXStream    *stream;
  140.  
  141.     savepanel = [[SaveAsPanel  new]  setSaveTo];
  142.     if ([savepanel    runModal])
  143.     {    
  144.         stream = NXOpenMemory(NULL, 0, NX_WRITEONLY);
  145.         if (stream)
  146.         {
  147.             [[windowId  contentView]  writePSToStream:stream];
  148.             NXSaveToFile(stream, [savepanel  filename]);
  149.             NXCloseMemory(stream, NX_FREEBUFFER);
  150.         }
  151.         else
  152.             Notify("Save Error", "Cannot open a stream to the file.");
  153.     }
  154.  
  155.     return self;
  156. }
  157.  
  158. @end
  159.  
  160.